package com.roshan.util;

import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;

import com.roshan.domain.LabelValue;

public class LabelValueComparator implements Comparator {
    private final Comparator c;

    /**
     * Creates a new LabelValueComparator object.
     * 
     * @param locale The Locale used for localized String comparison.
     */
    public LabelValueComparator(Locale locale) {
        c = Collator.getInstance(locale);
    }

    /**
     * Compares the localized labels of two LabelValues.
     * 
     * @param o1 The first LabelValue to compare.
     * @param o2 The second LabelValue to compare.
     * 
     * @return The value returned by comparing the localized labels.
     */
    @Override
    public final int compare(Object o1, Object o2) {
        LabelValue lhs = (LabelValue) o1;
        LabelValue rhs = (LabelValue) o2;

        return c.compare(lhs.getLabel(), rhs.getLabel());
    }
}
